<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* li:nth-child(2n){ 
             background-color: green; 
         } 
        li:nth-child(2n+1){ 
             background-color: red; 
         } */
         li:nth-child(n+5){
            background-color: green;
         }
         li:nth-child(-n+4){
            background-color: red;
         }
    </style>
</head>
<body>
    <ul>
        <li>li1</li>
        <li>li2</li>
        <li>li3</li>
        <li>li4</li>
        <li>li5</li>
        <li>li6</li>
        <li>li7</li>
        <li>li8</li>
        <li>li9</li>
        <li>li10</li>
        <li>li11</li>
        <li>li12</li>
    </ul>
</body>
</html>